package org.darkbits.cyklon.engine;

import java.util.Collections;
import java.util.List;
import java.util.Set;
import java.util.TreeSet;

import org.darkbits.cyklon.machine.Input;
import org.darkbits.cyklon.machine.Machine;
import org.darkbits.cyklon.machine.ProcessException;
import org.darkbits.cyklon.machine.Output;
import org.darkbits.cyklon.machine.Property;

public class ConnectedMachine implements Machine {
	Machine wrappedMachine;
	boolean enabled = true;
	Set<Connector> inputConnectors;
	Set<Connector> outputConnectors;
	
	public ConnectedMachine(Machine wrappedMachine) {
		this.wrappedMachine = wrappedMachine;
		this.inputConnectors = new TreeSet<Connector>();
		this.outputConnectors = new TreeSet<Connector>();
	}
	
	public void addInputConnector(Connector c) {
		inputConnectors.add(c);
	}
	
	public void addOutputConnector(Connector c) {
		outputConnectors.add(c);
	}
	
	public void removeInputConnector(Connector c) {
		inputConnectors.remove(c);
	}
	
	public void removeOutputConnector(Connector c) {
		outputConnectors.remove(c);
	}
	
	public Set<Connector> getInputConnectors() {
		return Collections.unmodifiableSet(inputConnectors);
	}
	
	public Set<Connector> getOutputConnectors() {
		return Collections.unmodifiableSet(outputConnectors);
	}

	public boolean isEnabled() {
		return enabled;
	}

	public void setEnabled(boolean enabled) {
		this.enabled = enabled;
	}

	public List<Input> getInputs() {
		return wrappedMachine.getInputs();
	}

	public Input getLeftInput() {
		return wrappedMachine.getLeftInput();
	}

	public Output getLeftOutput() {
		return wrappedMachine.getLeftOutput();
	}

	public Input getMonoInput() {
		return wrappedMachine.getMonoInput();
	}

	public Output getMonoOutput() {
		return wrappedMachine.getMonoOutput();
	}

	public List<Output> getOutputs() {
		return wrappedMachine.getOutputs();
	}

	public List<Property> getProperties() {
		return wrappedMachine.getProperties();
	}

	public Input getRightInput() {
		return wrappedMachine.getRightInput();
	}

	public Output getRightOutput() {
		return wrappedMachine.getRightOutput();
	}

	public void process(int samples) throws ProcessException {
		if (isEnabled()) {
			wrappedMachine.process(samples);
		}
	}
	
}
